﻿using Hazza.DigitalStore.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;


namespace Hazza.DigitalStore.Drivers
{
    public class DigitalContentPartDriver : ContentPartDriver<DigitalContentPart>
    {
        protected override string Prefix
        {
            get { return "DigitalContentPart"; }
        }

        protected override DriverResult Display(DigitalContentPart part, string displayType, dynamic shapeHelper)
        {
            return Combined(

                // Shape 1: Parts_DigitalContentPart
                ContentShape("Parts_DigitalContentPart", () => shapeHelper.Parts_DigitalContentPart(
                    Price: part.Price
                )),

                // Shape 2: Parts_DigitalContentPart_AddButton
                ContentShape("Parts_DigitalContentPart_AddButton", () => shapeHelper.Parts_DigitalContentPart_AddButton())
                );
        }

        protected override DriverResult Editor(DigitalContentPart part, dynamic shapeHelper)
        {
            return ContentShape("Parts_DigitalContentPart_Edit",
                () => shapeHelper.EditorTemplate(
                    TemplateName: "Parts/DigitalContentPart",
                    Model: part,
                    Prefix: Prefix));
        }

        protected override DriverResult Editor(DigitalContentPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            updater.TryUpdateModel(part, Prefix, null, null);
            return Editor(part, shapeHelper);
        }
    }
}